package cn.demoncat.util.web.config;

import cn.demoncat.util.web.intercept.AccessInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * WebMvc配置(spring-mvc)
 *
 * @author 延晓磊
 *
 * @since 2017年7月21日
 */
@ConditionalOnMissingBean(name = {"tokenInterceptor", "userTokenInterceptor"})
@Configuration
public class AccessWebMvcConfig implements WebMvcConfigurer {

	// 访问拦截器
	@Resource
	private AccessInterceptor accessInterceptor;
	
	/**
	 * 
	 * 功能描述：添加拦截器(interceptors)
	 *
	 * 
	 * @author 延晓磊
	 *
	 * @since 2017年7月21日
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 拦截路径
		String[] path = new String[] { "/**" };
		// 注册拦截器
		registry.addInterceptor(accessInterceptor).addPathPatterns(path).order(888);
	}
	
		
}
